package com.etime.shycourse.services.coupons.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.services.coupons.interfaces.CouponreciveServices;
import com.etime.shycourse.dao.CouponreciveMapper;
import com.etime.shycourse.dto.CouponreciveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类 优惠券领取记录
 * </p>
 *
 * @author wb
 * @since 2022-03-15
 */
@Service
public class CouponreciveServiceImpl implements CouponreciveServices {
    @Autowired
    private CouponreciveMapper mapper;

    /**
     * 优惠券使用记录日志 分页
     * <p></p>
     * 查询的条件:可根据
     * 优惠劵名模糊搜索 coupontitle
     * 优惠券使用状态 couponrecivestate
     * 领取时间区间 one two
     * 优惠券编号 couponno
     *
     * @param pageNum,        第几页       可不传
     * @param pageSize        一页多少数据  可不传          一
     * @param couponreciveDto
     * @return Page<CouponlogDto>
     */
    @Override
    public Page<CouponreciveDto> selectCouponReceivePage(CouponreciveDto couponreciveDto, Long pageNum, Long pageSize) {
        Page<CouponreciveDto> page;
        if (pageNum != null && pageSize != null) {
            page = new Page<> (pageNum, pageSize);
        } else {
            page = new Page<> ();
        }
        if (couponreciveDto.getCoupontitle () != null) {
            couponreciveDto.setCoupontitle("%" + couponreciveDto.getCoupontitle().trim() + "%");
        }
        if (couponreciveDto.getCouponreciveusername () != null) {
            couponreciveDto.setCouponreciveusername("%" + couponreciveDto.getCouponreciveusername().trim() + "%");
        }
        return mapper.selectCouponreciveDtoPage (couponreciveDto, page);
    }
}
